package com.juyu.miliao.api.dao.mysql;

import com.juyu.miliao.api.domain.*;
import com.juyu.miliao.api.domain.vo.DynamicInfoVo;
import com.juyu.miliao.api.domain.vo.WhitePacketDynamicDetailInfoVo;
import com.juyu.miliao.api.domain.vo.WhitePacketDynamicInfoVo;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * @author xuanqicheng
 * @create 2019-21-10:04
 */
@Repository
public class WhitePacketDynamicInfoDao {
    @Autowired
    private SqlSession sqlSession;

    public void addDynamciInfo(WhitePacketDynamicInfo dynamicInfo) {

        sqlSession.insert("addWhitePacketDynamciInfo",dynamicInfo);
    }

    public WhitePacketDynamicShareInfo getDynamicShareByDynamicId(Long dynamicId) {
        return sqlSession.selectOne("getWhitePackedDynamicShareByDynamicId",dynamicId);
    }

    public void addDynamicShare(Long dynamicId) {
        sqlSession.insert("addWhitePacketDynamicShare",dynamicId);
    }

    public void updateShareNumber(Long dynamicId) {
        sqlSession.update("updateWhitePacketShareNumber",dynamicId);
    }

    public void deleteDynamicInfo(long dynamicId) {
        sqlSession.update("deleteWhitePacketDynamicInfo",dynamicId);
    }

    /**
     * 查看动态动态列表
     * @param startNum
     * @param pageSize
     * @param appKey
     * @return
     */
    public List<WhitePacketDynamicInfoVo> getDynamicInfoList(int startNum, Integer pageSize,String appKey) {
        Map<String,Object> map = new HashMap<>(3);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        map.put("appKey",appKey);
        return sqlSession.selectList("selectWhitePacketDynamicListPage",map);
    }

    public List<WhitePacketDynamicInfoVo> selectDynamicListUserIdPage(String appKey,long userId, int startNum, Integer pageSize) {
        Map<String,Object>  map = new HashMap<>(2);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        map.put("userId",userId);
        map.put("appKey",appKey);
        return sqlSession.selectList("selectWhitePacketDynamicListUserIdPage",map);
    }

    public WhitePacketDynamicDetailInfoVo getDynamicInfoById(long dynamicId) {
        return  sqlSession.selectOne("getWhitePacketDynamicInfoById",dynamicId);
    }

    public void saveDynamicGiftInfo(WhitePacketDynamicGiftInfo dynamicGiftInfo) {
        sqlSession.insert("saveWhitePacketDynamicGiftInfo",dynamicGiftInfo);
    }

    public List<WhitePacketDynamicGiftInfo> getDynamicGiftListByDynamicId(long dynamicId) {
        return sqlSession.selectList("getWhitePacketDynamicGiftListByDynamicId",dynamicId);
    }

    public List<Long> getDynamicGiftUserList(long dynamicId) {
        return sqlSession.selectList("getWhitePacketDynamicGiftUserList",dynamicId);
    }

    public List<WhitePacketDynamicCommentInfo> getDynamicCommentPageByDynamicId(long dynamicId, int startNum, int pageSize) {
        Map<String,Object> map = new HashMap<>();
        map.put("dynamicId",dynamicId);
        map.put("startNum",startNum);
        map.put("pageSize",pageSize);
        return sqlSession.selectList("getWhitePacketDynamicCommentPageByDynamicId",map);
    }

    public List<WhitePacketDynamicInfoVo> selectDynamicListFollowPage(String appKey, List<Long> followUserList,
                                                                      int startNum, Integer pageSize) {
        Map<String,Object>  map = new HashMap<>(3);
        map.put("startNum",startNum);

        map.put("pageSize",pageSize);

        map.put("list",followUserList);

        map.put("appKey",appKey);

        return sqlSession.selectList("selectWhitePacketDynamicListFollowPage",map);
    }
}
